package com.example.chartmoudel;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;

import java.util.ArrayList;
import java.util.List;

import static com.example.chartmoudel.R.id.linechart;

/**
 * Created by xy on 2017/12/10.
 */

public class ChartActivity extends AppCompatActivity implements OnChartValueSelectedListener {
    private LineChart mLineChart;
    private PieChart mPieChart;
     List<String> list=new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mLineChart= (LineChart) findViewById(linechart);
        mPieChart= (PieChart) findViewById(R.id.piechart);
        LineChartManager.init(mLineChart);
        LineChartManager.setLimitLine(29);
        LineChartManager.setXValue(1);
        setDataLineChart();
//        mLineChart.setOnChartValueSelectedListener(this);

        for (int j = 0; j < 24; j++) {
            list.add(j+":00");
        }
        mLineChart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mLineChart.setMarker(new LineChartMarkerView(ChartActivity.this,R.layout.chart_marker,list));
            }
        });
        PieChartManger.init(mPieChart);
        setDataPieChart();

    }

    private void setDataPieChart() {
        List<PieEntry> list=new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            list.add(new PieEntry(i+10*3,"这是方块"+(i+1)));
        }
        List<Integer> colors=new ArrayList<>();
        colors.add(Color.BLUE);
        colors.add(Color.CYAN);
        colors.add(Color.RED);
        PieDataSet dataset=new PieDataSet(list,"");
        dataset.setColors(colors);
        mPieChart.setData(PieChartManger.setDataStyle(dataset));
    }

    private void setDataLineChart() {
        List<Entry> list=new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            list.add(new Entry(i,i+10*2));
        }
        LineDataSet dataSet=new LineDataSet(list,"");
        LineChartManager.setDataStyle(dataSet);
        LineData data=new LineData(dataSet);
        mLineChart.setData(data);

    }

    @Override
    public void onValueSelected(Entry e, Highlight h) {
//        mLineChart.setMarker(new LineChartMarkerView(this,R.layout.chart_marker,list));
    }

    @Override
    public void onNothingSelected() {

    }
}
